<!doctype html>
<html lang="en">
<head>
    <title>Recaf - modern bytecode editor</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="description" content="Recaf is a modern java bytecode editor using Objectweb's ASM and JavaFX.">
	<meta name="keywords" content="java,bytecode,editor,recaf,reverse engineering">
	<link rel="icon" type="image/x-icon" href="favicon.ico"/>
    <link rel="stylesheet" href="css/font/roboto300.css">
    <link rel="stylesheet" href="css/pure/pure-min.css">
    <link rel="stylesheet" href="css/pure/grids-responsive-min.css">
    <link rel="stylesheet" href="css/scroll.css">
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/menu.css">
    <link rel="stylesheet" href="css/code.css">
    <link rel="stylesheet" href="css/docs.css">
    <script src="js/jquery.min.js"></script>
</head>
<body id="root">
<header class="pure-menu pure-menu-horizontal">
    <a href="index.html"><div class="logo"></div></a>
    <nav>
        <ul class="pure-menu-list">
            <li class="pure-menu-item pure-menu-selected"><a href="documentation.html" class="pure-menu-link">Documentation</a></li>
            <li class="pure-menu-item"><a href="features.html" class="pure-menu-link">Features</a></li>
            <li class="pure-menu-item"><a href="https://github.com/Col-E/Recaf" class="pure-menu-link">Github</a></li>
        </ul>
    </nav>
</header>
<article>
    <div id="sidebar" class="column">
        <div class="pure-menu">
            <ul class="pure-menu-list">
                <li class="pure-menu-item"><span class="parent-menu">Setup</span>
                    <ul class="pure-menu-sub-list">
                        <li class="pure-menu-item"><a href="doc-setup-get.html" class="pure-menu-link">Getting Recaf</a></li>
                        <li class="pure-menu-item"><a href="doc-setup-8.html" class="pure-menu-link">Java 8</a></li>
                        <li class="pure-menu-item"><a href="doc-setup-11.html" class="pure-menu-link">Java 11+</a></li>
                    </ul>
                </li>
                <li class="pure-menu-item"><span class="parent-menu">Introduction</span>
                    <ul class="pure-menu-sub-list">
                        <li class="pure-menu-item"><a href="doc-intro-workspace.html" class="pure-menu-link">Workspaces</a></li>
                        <li class="pure-menu-item"><a href="doc-intro-config.html" class="pure-menu-link">Config</a></li>
                    </ul>
                </li>
                <li class="pure-menu-item"><span class="parent-menu">Searching</span>
                    <ul class="pure-menu-sub-list">
                        <li class="pure-menu-item"><a href="doc-search-string.html" class="pure-menu-link">Strings</a></li>
                        <li class="pure-menu-item"><a href="doc-search-value.html" class="pure-menu-link">Values</a></li>
                        <li class="pure-menu-item"><a href="doc-search-ref-class.html" class="pure-menu-link">Class references</a></li>
                        <li class="pure-menu-item"><a href="doc-search-ref-member.html" class="pure-menu-link">Member references</a></li>
                        <li class="pure-menu-item"><a href="doc-search-dec-member.html" class="pure-menu-link">Member declarations</a></li>
                        <li class="pure-menu-item"><a href="doc-search-instruction.html" class="pure-menu-link">Instructions</a></li>
                    </ul>
                </li>
                <li class="pure-menu-item"><span class="parent-menu">Editing</span>
                    <ul class="pure-menu-sub-list">
                        <li class="pure-menu-item"><a href="doc-edit-modes.html" class="pure-menu-link">Class modes</a></li>
                        <li class="pure-menu-item"><a href="doc-edit-mode-decompile.html" class="pure-menu-link">Decompile mode</a></li>
                        <li class="pure-menu-item"><a href="doc-edit-mode-table.html" class="pure-menu-link">Table mode</a></li>
                        <li class="pure-menu-item"><a href="doc-edit-mode-hex.html" class="pure-menu-link">Hex mode</a></li>
                        <li class="pure-menu-item"><a href="doc-edit-assembler.html" class="pure-menu-link">Assembler</a></li>
                        <ul class="pure-menu-sub-list">
                            <li class="pure-menu-item"><a href="doc-edit-assembler-errors.html" class="pure-menu-link">Errors</a></li>
                        </ul>
                    </ul>
                </li>
                <li class="pure-menu-item"><span class="parent-menu">Advanced</span>
                    <ul class="pure-menu-sub-list">
                        <li class="pure-menu-item"><a href="doc-advanced-theme.html" class="pure-menu-link">Themes</a></li>
                        <li class="pure-menu-item"><a href="doc-advanced-plugin.html" class="pure-menu-link">Plugins</a></li>
                        <li class="pure-menu-item"><a href="doc-advanced-scripting.html" class="pure-menu-link">Scripting</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <div id="content" class="column">
        <h1 id="assembler-modifying-fields-and-methods">Assembler: Modifying fields and methods</h1>
        <h2 id="how-to-access">How do you access the assembler?</h2>
        <center><video controls><source src="screenshots/assembler-access.mp4" type="video/mp4"></video></center>
        <p>When you right click a field or method definition in Recaf selecting <em>&quot;Edit with assembler&quot;</em> will open the assembler window. Fields and methods both use the same assembler system, but each use a different syntax for defining field or method specific properties.</p>
        <h2 id="method-assembler">Method Assembler</h2>
        <center><img src="screenshots/assembler-method.png"></center>
        <p>The method assembler lets you edit methods as text.</p>
        <p><strong>Features</strong></p>
        <ul>
            <li>Tab completion
            <ul>
                <li>Keywords (instruction opcodes)</li>
                <li>Instruction specific content (class types, field declarations, method declarations).</li>
            </ul>
            </li>
            <br><li>Code verification and analysis. After each keypress the code is analyzed for errors. Any error is shown both on the line number that caused it and in the bottom of the window in a list (clicking on list items will jump to the error line). In most cases the error is on the line that it says it is on. For more information on errors, see the post on understanding errors [click here for that].</li>
            <br><li>Named variables
            <ul>
                <li>The code analysis process allows referencing variables by names rather than indices.</li>
                <li>Classes that contain debug information will automatically disassemble variable instructions using variable names. If no debug information is found then the disassembler will fall back to using indices.</li>
            </ul>
            </li>
            <br><li>Right click context actions
            <ul>
                <li><strong>Labels</strong>: Navigate to the instructions that reference the label</li>
                <li><strong>Jumps</strong>: Navigate to the jump destination</li>
                <li><strong>Switches</strong>: Navigate to the switch case labels</li>
                <li><strong>Variables</strong>: Navigate to other variable instructions that refer to the same variable name/index</li>
                <li><strong>Class references</strong>: Show context menu for referenced class</li>
                <li><strong>Field references</strong>: Show context menu for referenced field</li>
                <li><strong>Method references</strong>: Show context menu for referenced method</li>
            </ul>
            </li>
        </ul>
        <h2 id="example">Example</h2>
        <p>Given the following Java code, lets take a look at the assembler</p>
<pre><span class="line"></span><span class="annotation">@Override</span>
<span class="line"></span><span class="keyword">public</span> <span class="keyword">double</span> accept(String expression) {
<span class="line"></span>    String matched = MatchUtil.match(<span class="string">&quot;^[-]?[0-9.]+[+-][-]?[0-9.]+&quot;</span>, expression);
<span class="line"></span>    String op = MatchUtil.findFirst(matched, <span class="string">&quot;+&quot;</span>, <span class="string">&quot;-&quot;</span>);
<span class="line"></span>    <span class="keyword">int</span> index = matched.indexOf(op);
<span class="line"></span>    String left = matched.substring(<span class="constant">0</span>, index);
<span class="line"></span>    String right = matched.substring(index + <span class="constant">1</span>, matched.length());
<span class="line"></span>    expression = expression.replace(matched, String.valueOf(<span class="keyword">switch</span> (op) {
<span class="line"></span>        <span class="keyword">case</span> <span class="string">&quot;+&quot;</span> -&gt; <span class="keyword">this</span>.evaluate(left) + <span class="keyword">this</span>.evaluate(right);
<span class="line"></span>        <span class="keyword">case</span> <span class="string">&quot;-&quot;</span> -&gt; <span class="keyword">this</span>.evaluate(left) - <span class="keyword">this</span>.evaluate(right);
<span class="line"></span>        <span class="keyword">default</span> -&gt; <span class="keyword">throw</span> <span class="keyword">new</span> IllegalStateException();
<span class="line"></span>    }));
<span class="line"></span>    <span class="keyword">return</span> <span class="keyword">this</span>.evaluate(expression);
<span class="line"></span>}
</pre>
        <table class="aligner">
            <tr>
                <td><span class="helper"/><img src="screenshots/assembler-example.png"></td>
                <td><span class="helper"/><img src="screenshots/assembler-example-locals.png"></td>
            </tr>
        </table>
        <h3 id="analysis">Analysis</h3>
        <p>The screenshot on the left shows the <em>Analysis</em> tab of the assembler window. This tab is shows information about the current line you have your cursor on. In the picture I have selected a line to make it more visible. There are two columns...</p>
        <p>The left column shows the value of variables at the given point. For primitive types and strings the exact value is simulated when possible.</p>
        <p>The right column shows the stack at the given point. The most recent items of the stack appear on the bottom of the list. In this case we can see that three strings are on the stack. The top of the stack contains <code>-</code> and just below it is <code>+</code>. Below that is an unknown string, loaded from the <code>matched</code> variable.</p>
        <h3 id="locals">Locals</h3>
        <p>The screenshot on the right shows a table displaying the current local variables. Unlike the analysis tab this does not show the value in the variable, just information about the variable. </p>
        <ul>
        <li>Index: The variable&#39;s local index</li>
        <li>Start/End: The labels in the method that indicate the scope of the variable</li>
        <li>Name: The variable&#39;s name as it was in the source code</li>
        <li>Descriptor: The variable&#39;s type</li>
        </ul>
        <p>You can immediately jump to any instruction that references a variable by right clicking on it in the table. This brings up the referrer menu.</p>
        <blockquote>
        <p><strong>See also</strong>:</p>
        <ul>
            <li><a href="doc-edit-assembler-errors.html"><em>&quot;Understanding assembler errors&quot;</em></a></li>
            <li><a href="doc-instructions.html"><em>&quot;Recaf's simplified bytecode format&quot;</em></a></li>    
        </ul>
        </blockquote>
        
        
        
        <h2 id="field-assembler">Field Assembler</h2>
        <center><img src="screenshots/assembler-field.png"></center>
        <p>The field assembler lets you edit fields as text.</p>
        <ul>
            <li>The field assembler does not have any specific features at the moment.</li>
        </ul>
        
        
        
        <br id="spacing-hack">
    </div>
</article> 
</body>
</html>
